package com.amap.api.col.s;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import com.amap.api.col.s.cf;
import com.amap.api.services.core.AMapException;
import com.amap.api.services.interfaces.IRouteSearchV2;
import com.amap.api.services.route.BusRouteResultV2;
import com.amap.api.services.route.DriveRouteResultV2;
import com.amap.api.services.route.RideRouteResultV2;
import com.amap.api.services.route.RouteSearchV2;
import com.amap.api.services.route.WalkRouteResultV2;

/* compiled from: RouteSearchCoreV2.java */
/* loaded from: classes.dex */
public final class bs implements IRouteSearchV2 {
    private RouteSearchV2.OnRouteSearchListener a;
    private Context b;
    private Handler c;

    public bs(Context context) throws AMapException {
        cg a = cf.a(context, m.a(false));
        if (a.a != cf.c.SuccessCode) {
            throw new AMapException(a.b, 1, a.b, a.a.a());
        }
        this.b = context.getApplicationContext();
        this.c = y.a();
    }

    private static boolean a(RouteSearchV2.FromAndTo fromAndTo) {
        return (fromAndTo == null || fromAndTo.getFrom() == null || fromAndTo.getTo() == null) ? false : true;
    }

    @Override // com.amap.api.services.interfaces.IRouteSearchV2
    public final void setRouteSearchListener(RouteSearchV2.OnRouteSearchListener onRouteSearchListener) {
        this.a = onRouteSearchListener;
    }

    @Override // com.amap.api.services.interfaces.IRouteSearchV2
    public final DriveRouteResultV2 calculateDriveRoute(RouteSearchV2.DriveRouteQuery driveRouteQuery) throws AMapException {
        try {
            w.a(this.b);
            if (driveRouteQuery == null) {
                throw new AMapException(AMapException.AMAP_CLIENT_INVALID_PARAMETER);
            }
            if (!a(driveRouteQuery.getFromAndTo())) {
                throw new AMapException(AMapException.AMAP_CLIENT_INVALID_PARAMETER);
            }
            ap.a();
            ap.b(driveRouteQuery.getPassedByPoints());
            ap.a().c(driveRouteQuery.getAvoidpolygons());
            RouteSearchV2.DriveRouteQuery m30clone = driveRouteQuery.m30clone();
            DriveRouteResultV2 c = new s(this.b, m30clone).c();
            if (c != null) {
                c.setDriveQuery(m30clone);
            }
            return c;
        } catch (AMapException e) {
            n.a(e, "RouteSearch", "calculateDriveRoute");
            throw e;
        }
    }

    @Override // com.amap.api.services.interfaces.IRouteSearchV2
    public final void calculateDriveRouteAsyn(final RouteSearchV2.DriveRouteQuery driveRouteQuery) {
        try {
            ax.a().a(new Runnable() { // from class: com.amap.api.col.s.bs.1
                {
                    bs.this = this;
                }

                @Override // java.lang.Runnable
                public final void run() {
                    Message obtainMessage = y.a().obtainMessage();
                    obtainMessage.what = 101;
                    obtainMessage.arg1 = 101;
                    Bundle bundle = new Bundle();
                    DriveRouteResultV2 driveRouteResultV2 = null;
                    try {
                        try {
                            driveRouteResultV2 = bs.this.calculateDriveRoute(driveRouteQuery);
                            bundle.putInt("errorCode", 1000);
                        } catch (AMapException e) {
                            bundle.putInt("errorCode", e.getErrorCode());
                        }
                    } finally {
                        obtainMessage.obj = bs.this.a;
                        bundle.putParcelable("result", driveRouteResultV2);
                        obtainMessage.setData(bundle);
                        bs.this.c.sendMessage(obtainMessage);
                    }
                }
            });
        } catch (Throwable th) {
            n.a(th, "RouteSearch", "calculateDriveRouteAsyn");
        }
    }

    @Override // com.amap.api.services.interfaces.IRouteSearchV2
    public final WalkRouteResultV2 calculateWalkRoute(RouteSearchV2.WalkRouteQuery walkRouteQuery) throws AMapException {
        try {
            w.a(this.b);
            if (walkRouteQuery == null) {
                throw new AMapException(AMapException.AMAP_CLIENT_INVALID_PARAMETER);
            }
            if (!a(walkRouteQuery.getFromAndTo())) {
                throw new AMapException(AMapException.AMAP_CLIENT_INVALID_PARAMETER);
            }
            ap.a().b(walkRouteQuery.getFromAndTo());
            RouteSearchV2.WalkRouteQuery m33clone = walkRouteQuery.m33clone();
            WalkRouteResultV2 c = new ba(this.b, m33clone).c();
            if (c != null) {
                c.setWalkQuery(m33clone);
            }
            return c;
        } catch (AMapException e) {
            n.a(e, "RouteSearch", "calculateWalkRoute");
            throw e;
        }
    }

    @Override // com.amap.api.services.interfaces.IRouteSearchV2
    public final void calculateWalkRouteAsyn(final RouteSearchV2.WalkRouteQuery walkRouteQuery) {
        try {
            ax.a().a(new Runnable() { // from class: com.amap.api.col.s.bs.2
                {
                    bs.this = this;
                }

                @Override // java.lang.Runnable
                public final void run() {
                    Message obtainMessage = y.a().obtainMessage();
                    obtainMessage.what = 102;
                    obtainMessage.arg1 = 101;
                    Bundle bundle = new Bundle();
                    WalkRouteResultV2 walkRouteResultV2 = null;
                    try {
                        try {
                            walkRouteResultV2 = bs.this.calculateWalkRoute(walkRouteQuery);
                            bundle.putInt("errorCode", 1000);
                        } catch (AMapException e) {
                            bundle.putInt("errorCode", e.getErrorCode());
                        }
                    } finally {
                        obtainMessage.obj = bs.this.a;
                        bundle.putParcelable("result", walkRouteResultV2);
                        obtainMessage.setData(bundle);
                        bs.this.c.sendMessage(obtainMessage);
                    }
                }
            });
        } catch (Throwable th) {
            n.a(th, "RouteSearch", "calculateWalkRouteAsyn");
        }
    }

    @Override // com.amap.api.services.interfaces.IRouteSearchV2
    public final RideRouteResultV2 calculateRideRoute(RouteSearchV2.RideRouteQuery rideRouteQuery) throws AMapException {
        try {
            w.a(this.b);
            if (rideRouteQuery == null) {
                throw new AMapException(AMapException.AMAP_CLIENT_INVALID_PARAMETER);
            }
            if (!a(rideRouteQuery.getFromAndTo())) {
                throw new AMapException(AMapException.AMAP_CLIENT_INVALID_PARAMETER);
            }
            ap.a().a(rideRouteQuery.getFromAndTo());
            RouteSearchV2.RideRouteQuery m32clone = rideRouteQuery.m32clone();
            RideRouteResultV2 c = new as(this.b, m32clone).c();
            if (c != null) {
                c.setRideQuery(m32clone);
            }
            return c;
        } catch (AMapException e) {
            n.a(e, "RouteSearch", "calculaterideRoute");
            throw e;
        }
    }

    @Override // com.amap.api.services.interfaces.IRouteSearchV2
    public final void calculateRideRouteAsyn(final RouteSearchV2.RideRouteQuery rideRouteQuery) {
        try {
            ax.a().a(new Runnable() { // from class: com.amap.api.col.s.bs.3
                {
                    bs.this = this;
                }

                @Override // java.lang.Runnable
                public final void run() {
                    Message obtainMessage = y.a().obtainMessage();
                    obtainMessage.what = 103;
                    obtainMessage.arg1 = 101;
                    Bundle bundle = new Bundle();
                    RideRouteResultV2 rideRouteResultV2 = null;
                    try {
                        try {
                            rideRouteResultV2 = bs.this.calculateRideRoute(rideRouteQuery);
                            bundle.putInt("errorCode", 1000);
                        } catch (AMapException e) {
                            bundle.putInt("errorCode", e.getErrorCode());
                        }
                    } finally {
                        obtainMessage.obj = bs.this.a;
                        bundle.putParcelable("result", rideRouteResultV2);
                        obtainMessage.setData(bundle);
                        bs.this.c.sendMessage(obtainMessage);
                    }
                }
            });
        } catch (Throwable th) {
            n.a(th, "RouteSearch", "calculateRideRouteAsyn");
        }
    }

    @Override // com.amap.api.services.interfaces.IRouteSearchV2
    public final BusRouteResultV2 calculateBusRoute(RouteSearchV2.BusRouteQuery busRouteQuery) throws AMapException {
        try {
            w.a(this.b);
            if (busRouteQuery == null) {
                throw new AMapException(AMapException.AMAP_CLIENT_INVALID_PARAMETER);
            }
            if (!a(busRouteQuery.getFromAndTo())) {
                throw new AMapException(AMapException.AMAP_CLIENT_INVALID_PARAMETER);
            }
            RouteSearchV2.BusRouteQuery m29clone = busRouteQuery.m29clone();
            BusRouteResultV2 c = new h(this.b, m29clone).c();
            if (c != null) {
                c.setBusQuery(m29clone);
            }
            return c;
        } catch (AMapException e) {
            n.a(e, "RouteSearch", "calculateBusRoute");
            throw e;
        }
    }

    @Override // com.amap.api.services.interfaces.IRouteSearchV2
    public final void calculateBusRouteAsyn(final RouteSearchV2.BusRouteQuery busRouteQuery) {
        try {
            ax.a().a(new Runnable() { // from class: com.amap.api.col.s.bs.4
                {
                    bs.this = this;
                }

                @Override // java.lang.Runnable
                public final void run() {
                    Message obtainMessage = y.a().obtainMessage();
                    obtainMessage.what = 100;
                    obtainMessage.arg1 = 101;
                    Bundle bundle = new Bundle();
                    BusRouteResultV2 busRouteResultV2 = null;
                    try {
                        try {
                            busRouteResultV2 = bs.this.calculateBusRoute(busRouteQuery);
                            bundle.putInt("errorCode", 1000);
                        } catch (AMapException e) {
                            bundle.putInt("errorCode", e.getErrorCode());
                        }
                    } finally {
                        obtainMessage.obj = bs.this.a;
                        bundle.putParcelable("result", busRouteResultV2);
                        obtainMessage.setData(bundle);
                        bs.this.c.sendMessage(obtainMessage);
                    }
                }
            });
        } catch (Throwable th) {
            n.a(th, "RouteSearch", "calculateBusRouteAsyn");
        }
    }
}
